/*
package com.its.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.its.manager.mapper.PermissionMapper;
import com.its.manager.mapper.RoleMapper;
import com.its.manager.mapper.RolePermissionMapper;
import com.its.manager.pojo.Permission;
import com.its.manager.pojo.Role;
import com.its.manager.pojo.RolePermission;
import com.its.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

*/
/**
* @author lenovo
* @description 针对表【gym_role】的数据库操作Service实现
* @createDate 2025-04-15 23:33:47
*//*

@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    //注入Mapper层属性
    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private RolePermissionMapper rolePermissionMapper;

    @Autowired
    private PermissionMapper permissionMapper;

    //新增角色
    @Override
    public int addRoleService(Role role) {
        return roleMapper.insert(role);
    }

    //修改角色
    @Override
    public int updateRoleService(Role role) {
        return roleMapper.updateById(role);
    }

    //删除角色
    @Transactional
    @Override
    public int deleteRoleService(Long rid) {
        //删除角色的权限信息
        QueryWrapper<Permission> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("rid",rid);
        rolePermissionMapper.deleteById(rid);
        //删除角色
        int i = roleMapper.deleteById(rid);
        return i;
    }

    //根据ID查询角色
    */
/*@Override
    public Role selectRoleByIdService(Long rid) {
        //查询角色信息
        Role role = new Role();
        //查询角色Id
        QueryWrapper<RolePermission> roleQueryWrapper = new QueryWrapper<>();
        roleQueryWrapper.eq("rid",rid);
        roleQueryWrapper.select("pid");
        List<Object> pids = rolePermissionMapper.selectObjs(roleQueryWrapper);
        //查询权限信息
        List<Permission> permissions = permissionMapper.selectBatchIds(pids.stream().map(obj -> (Long) obj).collect(Collectors.toList()));
        //存储到role对象中
        role.setPermissions(permissions);
        return role;
    }*//*


    //分页查询角色信息
    @Override
    public Page<Role> selectRoleByPageService(Integer page, Integer size) {
        Page<Role> rolePage = roleMapper.selectPage(new Page<>(page, size), null);
        return rolePage;
    }

    //修改角色权限
    @Transactional
    @Override
    public int updateRoleService(Long rid, Long[] pids) {
        //修改--先删除，后增加
        int delete = rolePermissionMapper.deleteById(new QueryWrapper<>().eq("rid", rid));
        //增加角色信息
        for (Long pid : pids) {
            RolePermission rolePermission = new RolePermission();
            rolePermission.setPid(pid);
            rolePermission.setRid(rid);
            rolePermissionMapper.insert(rolePermission);
        }
        return delete;
    }
}




*/
